package com.biz.primus.management.depot.init;

import com.biz.primus.account.service.AuthInitializeService;
import com.biz.primus.base.enums.CommonStatus;
import com.biz.primus.model.sso.auth.vo.GrantedAuthority;
import com.biz.primus.model.sso.auth.vo.MenuGroupVO;
import com.biz.primus.model.sso.auth.vo.MenuItemVO;
import com.biz.primus.model.sso.auth.vo.ResourceVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import static com.google.common.collect.Lists.newArrayList;

/**
 *
 *@Auther JKLiues
 *@Date 2017/9/21
 */
@Service
public class InitManager {

    private final AuthInitializeService authInitializeService;

    @Autowired
    public InitManager(AuthInitializeService authInitializeService) {
        this.authInitializeService = authInitializeService;
    }

//    @PostConstruct
    public void setup() {

        List<MenuGroupVO> menuGroups = newArrayList();
        MenuGroupVO menuGroupVO = new MenuGroupVO("MANAGEMENT_DEPOT", "门店管理", "门店管理", "fa fa-cogs", CommonStatus.ENABLE, 888);
        List<MenuItemVO> menuItems = newArrayList();
        MenuItemVO menuManageMenuItemVO = new MenuItemVO("MANAGEMENT_DEPOT", "门店管理", "门店列表", "fa fa-list", "depots/list.do", CommonStatus.ENABLE, 1);
        menuManageMenuItemVO.setGrantedAuthority(new GrantedAuthority("ROLE_DEPOT;OPT_DEPOT_LIST"));
        List<ResourceVO> resources = newArrayList();
        resources.add(new ResourceVO("MANAGEMENT_DEPOT_DETAIL", "详情", "门店详情", CommonStatus.ENABLE, new GrantedAuthority("OPT_DEPOT_DETAIL"), 1));
        resources.add(new ResourceVO("MANAGEMENT_DEPOT_UPDATE", "更新状态", "更新状态", CommonStatus.ENABLE, new GrantedAuthority("OPT_DEPOT_UPDATE"), 2));
        menuManageMenuItemVO.setResources(resources);
        menuItems.add(menuManageMenuItemVO);
        menuGroupVO.setMenuItems(menuItems);
        menuGroups.add(menuGroupVO);
        authInitializeService.registerMenu(menuGroups);

    }
}
